//
//  DHSmallProgramNative.m
//  
//
//  Created by MAC on 2018/6/27.
//

#import "DHSmallProgramNative.h"
#import "WXApi.h"
#import "WXApiObject.h"

@implementation DHSmallProgramNative

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(shareWechatSmallProgram:(NSDictionary *)dics){
  
    [self shareSmallProgramMethod:dics[@"picUrl"] webpageUrl:dics[@"webpageUrl"] userName:dics[@"userName"]];
}

- (void)shareSmallProgramMethod:(NSString *)picUrl webpageUrl:(NSString *)webpageUrl userName:(NSString *)userName
{
    NSData* imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:picUrl]];
    UIImage* resultImage = [UIImage imageWithData: imageData];
    UIImage *thumbImage = resultImage;
    WXMiniProgramObject *ext = [WXMiniProgramObject object];
    ext.webpageUrl = webpageUrl;
    ext.userName = userName;
    ext.hdImageData = imageData;
    ext.miniProgramType = 0;

    WXMediaMessage *message = [WXMediaMessage message];
    message.title = @"美肌工坊";
    message.mediaObject = ext;
    [message setThumbImage:thumbImage];
    
    SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
    req.message = message;
    dispatch_async(dispatch_get_main_queue(), ^{
        [WXApi sendReq:req];
    });

}
#pragma mark - WXApiManagerDelegate



@end
